﻿using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using AutoRevit;
using AutoRevit.Entry.Command;
using AutoRevitDemo.Events;

namespace AutoRevitDemo.TestExternalCommand;

public class AutoGeneratorCommand
{
    const string Namespace = "MyNamespace.Command";

    [AutoExternalCommand(
        JournalingMode = nameof(JournalingMode.UsingCommandData),
        RegenerationOption = nameof(RegenerationOption.Manual))]
    internal static Result GetWall(ExternalCommandData CommandData, ref string msg)
    {
        try
        {
            // 业务代码
            var addEvent = ExternalEvent.CreateJournalable(new AddEventAutoExternalEventHandler());

            var addEventResult = addEvent.Raise();

            var removeEvent = ExternalEvent.CreateJournalable(new RemoveEvent());

            var removeEventResult = removeEvent.Raise();

            return Result.Succeeded;
        }
        catch (Exception ex)
        {
            msg = ex.Message;
            return Result.Failed;
        }
    }

    [AutoExternalCommand(TransactionMode = nameof(TransactionMode.ReadOnly))]
    internal static Result GetPanel(ExternalCommandData CommandData)
    {
        return Result.Succeeded;
    }

    [AutoExternalCommand(ClassName = "DeleteWallCommand")]
    internal static Result DeleteWall(IRevitData revitData)
    {
        revitData.ResultMessage = "删除错误";

        return Result.Failed;
    }

    [AutoExternalCommand]
    internal static Result YouerFunc()
    {
        return Result.Succeeded;
    }

    [AutoExternalCommand(Namespace = Namespace)]
    internal static Result LoadData()
    {
        return Result.Succeeded;
    }
}